﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace YDT.Payment.Application
{
    /// <summary>
    /// 支付接口选择
    /// </summary>
    public class WebPagePayFactory
    {
        private readonly Dictionary<string, IWebPagePay> _webPagePays =null;

        public WebPagePayFactory(IEnumerable<IWebPagePay> webPagePays)
        {
            _webPagePays = webPagePays.ToDictionary(pay =>
            {
                return pay.GetType().Name; // AliPagePay  WxNativePay
            });
        }

        /// <summary>
        /// 获取WebPagePay支付
        /// </summary>
        /// <param name="pageType"></param>
        public IWebPagePay GetWebPagePay(string pageType)
        {
            if (string.IsNullOrEmpty(pageType))
            {
                return _webPagePays["WxNativePay"];
            }
            return _webPagePays[pageType];
        }
    }
}
